import javax.swing.*;
import java.awt.*;

public class GameFrame extends JFrame {
    final int frameSize = 600;
    final int step = 30;


    //蛇头对象
    SnakeHead snakeHead = new SnakeHead(GameUtils.rightImg, 30, 570, this);
    public void  launch(){
        //设置窗口是否可见
        this.setVisible(true);
        //设置窗口是否可见
        this.setSize(frameSize,frameSize);
        //设置窗口的位置在屏幕上居中
        this.setLocationRelativeTo(null);
        //设置窗口的名字
        this.setTitle("贪吃蛇");
        //设置窗口关闭策略 JFrame.EXIT_ON_CLOSE：窗口关闭则程序退出
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    @Override
    public void paint(Graphics graphics){
        //灰色背景
        graphics.setColor(Color.gray);
        graphics.fillRect(0,0,frameSize,frameSize);
        //设置背景
        graphics.setColor(Color.black);
        int lineNum = frameSize / step;
        for (int i =0; i <= lineNum; i++){
            //绘制竖线
            graphics.drawLine(0,i*step,frameSize, i*step);
            //绘制横线
            graphics.drawLine(i*step,0, i*step, frameSize);
        }
        //在窗口中绘制蛇头
        snakeHead.paintSelf(graphics);
    }

    public static void main(String[] args) {
        GameFrame gameFrame = new GameFrame();
        gameFrame.launch();
    }
}
